//
//  MainViewController.swift
//  Weibo
//
//  Created by apple on 16/1/10.
//  Copyright © 2016年 apple. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {

    
    //MARK: 按钮的监听事件
    @objc private func plusBtnDidClick() {
        print(__FUNCTION__)
    }
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        //系统 的tabBar是 只读属性 不能够直接修改
        //可以使用kvc 间接修改 
        print(tabBar.classForCoder)
        let mainTabbar = MainTabbar()
        setValue(mainTabbar, forKey: "tabBar")
        //Selector("plusBtnDidClick") 类型实例
        mainTabbar.plusBtn.addTarget(self, action: "plusBtnDidClick", forControlEvents: .TouchUpInside)
        print(tabBar.classForCoder)
        //根控制器的入口
        addChildViewControllers()
    }
    
    
    private func addChildViewControllers() {
        //首页
        addChildViewController(HomeTableViewController(), imageName: "tabbar_home", title: "首页")
        //消息
        addChildViewController(MessageTableViewController(), imageName: "tabbar_message_center", title: "消息")
        //发现
        addChildViewController(DiscoverTableViewController(), imageName: "tabbar_discover", title: "发现")
        //我
        addChildViewController(ProfileTableViewController(), imageName: "tabbar_profile", title: "我")
    }
    ///添加子视图控制器
    private func addChildViewController(vc: UIViewController,imageName: String,title: String) {
        //实例化 VC
        //设置图片
        vc.tabBarItem.image = UIImage(named: imageName)
        //设置item选中的图片 //手写代码修改图片显示样式
        self.tabBar.tintColor = UIColor.orangeColor()
//        vc.tabBarItem.selectedImage = UIImage(named: imageName + "_highlighted")?.imageWithRenderingMode(.AlwaysOriginal)
//        //
//        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.orangeColor()], forState: .Selected)
        
        //设置title
//        home.tabBarItem.title = "首页"_highlighted
//        home.navigationItem.title = "首页"
        vc.title = title
        
        //导航控制器
        let nav = UINavigationController(rootViewController: vc)
        
        
        //添加子视图控制器
        addChildViewController(nav)
    }
    
    

}
